package com.ruoyi.data.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.data.domain.vo.DataMd5Vo;
import com.ruoyi.data.domain.bo.DataMd5Bo;
import com.ruoyi.data.service.IDataMd5Service;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户md5列
 *
 * @author ruoyi
 * @date 2023-12-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dataMd5/md5")
public class DataMd5Controller extends BaseController {

    private final IDataMd5Service iDataMd5Service;

    /**
     * 查询用户md5列列表
     */
    @SaCheckPermission("dataMd5:md5:list")
    @GetMapping("/list")
    public TableDataInfo<DataMd5Vo> list(DataMd5Bo bo, PageQuery pageQuery) {
        return iDataMd5Service.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户md5列列表
     */
    @SaCheckPermission("dataMd5:md5:export")
    @Log(title = "用户md5列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DataMd5Bo bo, HttpServletResponse response) {
        List<DataMd5Vo> list = iDataMd5Service.queryList(bo);
        ExcelUtil.exportExcel(list, "用户md5列", DataMd5Vo.class, response);
    }

    /**
     * 获取用户md5列详细信息
     *
     * @param dataMd5Id 主键
     */
    @SaCheckPermission("dataMd5:md5:query")
    @GetMapping("/{dataMd5Id}")
    public R<DataMd5Vo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long dataMd5Id) {
        return R.ok(iDataMd5Service.queryById(dataMd5Id));
    }

    /**
     * 新增用户md5列
     */
    @SaCheckPermission("dataMd5:md5:add")
    @Log(title = "用户md5列", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DataMd5Bo bo) {
        return toAjax(iDataMd5Service.insertByBo(bo));
    }

    /**
     * 修改用户md5列
     */
    @SaCheckPermission("dataMd5:md5:edit")
    @Log(title = "用户md5列", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DataMd5Bo bo) {
        return toAjax(iDataMd5Service.updateByBo(bo));
    }

    /**
     * 删除用户md5列
     *
     * @param dataMd5Ids 主键串
     */
    @SaCheckPermission("dataMd5:md5:remove")
    @Log(title = "用户md5列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataMd5Ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] dataMd5Ids) {
        return toAjax(iDataMd5Service.deleteWithValidByIds(Arrays.asList(dataMd5Ids), true));
    }
}
